package com.example.wl.tiaoyinqi.yueqifragments;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.wl.tiaoyinqi.MyCallbacks;
import com.example.wl.tiaoyinqi.QinxianView;
import com.example.wl.tiaoyinqi.R;

/**
 * Created by wl on 2016/5/30.
 */
public abstract class HengxianYueqiFragmen extends Fragment {
    private MyCallbacks mCallbacks;

    abstract int getLayoutResId();

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mCallbacks = (MyCallbacks) context;
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mCallbacks = null;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(getLayoutResId(), container, false);
        QinxianView qinxianView = (QinxianView) v.findViewById(R.id.qinxianView);
        qinxianView.setLeftMargin(getLeftMargins());
        qinxianView.setLeftTopMargin(getLeftTopMargins());
        qinxianView.setRightTopMargin(getRightTopMargins());
        qinxianView.setQinzhenLeftMargin(getQinzhenLeftMargins());
        qinxianView.setOnXianClickListener(new QinxianView.onXianClickListener() {
            @Override
            public void xianClick(int position) {
                mCallbacks.onXianClick(position);
            }
        });
        return v;
    }

    public int[] getLeftMargins() {
        return new int[]{
                187, 126, 78, 46, 27,
                17, 18, 29, 49, 77,
                112, 160, 225, 309, 410
        };
    }

    public int[] getLeftTopMargins() {
        return new int[]{
                333, 427, 522, 617, 713,
                806, 902, 998, 1092, 1188,
                1283, 1377, 1472, 1567, 1663
        };
    }

    public int[] getRightTopMargins() {
        return new int[]{
                455, 549, 628, 717, 787,
                853, 928, 1004, 1070, 1147,
                1231, 1325, 1413, 1520, 1627
        };
    }

    public int[] getQinzhenLeftMargins(){
        return new int[15];
    }
}
